import java.util.HashMap;

public class Test01 {
    public int[] twoSum(int[] nums, int target) {
        int num1 = 0, num2 = 0;
        int[] res = new int[2];
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            num1 = nums[i];
            num2 = target - num1;
            int ret = map.getOrDefault(num2, -1);
            if (ret == -1) {
                map.put(num1, i);
            } else {
                res[0] = i;
                res[1] = ret;
            }

        }
        return res;
    }
}
